namespace Bootsy.Dict

import Bootsy.Core
import Bootsy.Dict.RPC
import Bootsy.PEG

class DictBot(GrammarBasedBot):
	
	final _service = DictService()
	
	def constructor():
		super(SetUpGrammar())
		
	def SetUpGrammar():
		return literal("!dict") >> remaining(Search) >> eof()
		
	def Search(text as string, message as IChatMessage):
		definition = _service.Define(text)
		if 0 == len(definition.Definitions):
			message.Chat.PostMessage("No definitions for '${text}'")
		else:
			message.Chat.PostMessage(definition.Definitions[0].WordDefinition)
